package sg.edu.nus.iss.billing.vo.login;

import java.util.Date;

import sg.edu.nus.iss.billing.common.DbUtil;
import sg.edu.nus.iss.billing.common.exception.InvalidParamsException;
import sg.edu.nus.iss.billing.vo.common.IDbSerialisable;

public class LoginVO implements IDbSerialisable {
	
	private String userID;
	private String password;
	private String userRole;
	private Date loginTme;
	private String status;
	
	public LoginVO(String userID, String password) {
		super();
		this.userID = userID;
		this.password = password;
	}

	public LoginVO() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
	/**
	 * @return the userID
	 */
	public String getUserID() {
		return userID;
	}
	/**
	 * @param userID the userID to set
	 */
	public void setUserID(String userID) {
		this.userID = userID;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return the userRole
	 */
	public String getUserRole() {
		return userRole;
	}
	/**
	 * @param userRole the userRole to set
	 */
	public void setUserRole(String userRole) {
		this.userRole = userRole;
	}
	/**
	 * @return the loginTme
	 */
	public Date getLoginTme() {
		return loginTme;
	}
	/**
	 * @param loginTme the loginTme to set
	 */
	public void setLoginTme(Date loginTme) {
		this.loginTme = loginTme;
	}

	@Override
	public void setParameters(String serialisedEntry)
			throws InvalidParamsException {
		// vipuladm^password^admin
		String[] tokens =  serialisedEntry.split(java.util.regex.Pattern.quote(DbUtil.DELIMITER));
		if (tokens.length != 3) {
			throw new InvalidParamsException("Expected 3 parameters, received " + tokens.length);
		} else {
			setUserID(tokens[0]); 
			setPassword(tokens[1]);
			setUserRole(tokens[2]);
		}
	}

	@Override
	public String serialised() {
		StringBuilder sb = new StringBuilder();
		sb.append(getUserID());
		sb.append(DbUtil.DELIMITER);
		sb.append(getPassword());
		sb.append(DbUtil.DELIMITER);
		sb.append(getUserRole());
		return sb.toString();
	}
}
